home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 055 (1988-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 055 (1988-05-15)(Ossowski, Stefan)(DE)(PD).adf / Berserk / graph.c < prev    next >
C/C++ Source or Header  |  1988-04-10  |  1KB  |  78 lines

  1. /*  :ts=8 bk=0  */
  2. #include <exec/types.h>
  3. #include <intuition/intuition.h>
  4.  
  5. extern void    *OpenLibrary(), *OpenWindow();
  6.  
  7. struct NewWindow windef = {
  8.     320, 0, 320, 100,
  9.     -1, -1,
  10.     NULL,
  11.     WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH,
  12.     NULL, NULL,
  13.     (UBYTE *) "Graph output",
  14.     NULL, NULL,
  15.     0, 0, 0, 0,
  16.     WBENCHSCREEN
  17. };
  18.  
  19. struct Window    *win;
  20. void        *IntuitionBase, *GfxBase;
  21.  
  22. main ()
  23. {
  24.     register struct RastPort *rp;
  25.     float gravity, v1, start, end, step, x, y;
  26.  
  27.     openstuff ();
  28.     rp = win -> RPort;
  29.  
  30.     printf ("Enter gravity: ");
  31.     scanf ("%f", &gravity);
  32.     printf ("Enter initial velocity: ");
  33.     scanf ("%f", &v1);
  34.     printf ("Enter start and ending X: ");
  35.     scanf ("%f %f", &start, &end);
  36.     printf ("Enter step rate: ");
  37.     scanf ("%f", &step);
  38.  
  39.     for (x=start; x<=end; x+=step) {
  40.         y = -gravity * (x*x) + v1*x;
  41.         WritePixel (rp, (long) x+20, (long) (97.-y/2.));
  42.     }
  43.  
  44.     getchar ();
  45.     getchar ();
  46.     closestuff ();
  47. }
  48.  
  49.  
  50.  
  51.  
  52. openstuff ()
  53. {
  54.     if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L)))
  55.         die ("-=RJ=-'s missing.");
  56.  
  57.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L)))
  58.         die ("Dale's missing.");
  59.  
  60.     if (!(win = OpenWindow (&windef)))
  61.         die ("Window painted shut.");
  62. }
  63.  
  64. closestuff ()
  65. {
  66.     if (win)        CloseWindow (win);
  67.     if (GfxBase)        CloseLibrary (GfxBase);
  68.     if (IntuitionBase)    CloseLibrary (IntuitionBase);
  69. }
  70.  
  71. die (str)
  72. char *str;
  73. {
  74.     puts (str);
  75.     closestuff ();
  76.     exit (20);
  77. }
  78.